package com.duoduo.algs4.util;

import edu.princeton.cs.introcs.StdOut;

public class ArrayUtil<T> {
	public void printDoubleArray(T[][] a) throws Exception {
		int M = a.length;
		if (M <= 0) {
			throw new Exception("数组维度应该大于0");
		}
		int N = a[0].length;
		if (N <= 0) {
			throw new Exception("数组维度应该大于0");
		}
		System.out.println("二维数组为:");
		for (int i = 0; i < M; i++) {
			for (int j = 0; j < N; j++) {
				System.out.print(a[i][j] + " ");
			}
			System.out.println();
		}
	}
	public static void printDoubleArray(int[][] a) throws Exception {
		int M = a.length;
		if (M <= 0) {
			throw new Exception("数组维度应该大于0");
		}
		int N = a[0].length;
		if (N <= 0) {
			throw new Exception("数组维度应该大于0");
		}
		System.out.println("二维数组为:");
		for (int i = 0; i < M; i++) {
			for (int j = 0; j < N; j++) {
				System.out.print(a[i][j] + " ");
			}
			System.out.println();
		}
	}

	public void printxArray(T[] a) {
		int M = a.length;
		System.out.println("数组为:");
		for (int i = 0; i < M; i++) {
			System.out.print(a[i] + " ");
		}
		System.out.println();
	}

	public static void printArray(int[] a) {
		int M = a.length;
		StdOut.println("数组为:");
		for (int i = 0; i < M; i++) {
			StdOut.print(a[i] + " ");
		}
		StdOut.println();
	}

	public static void printArray(double[] a) {
		int M = a.length;
		StdOut.println("数组为:");
		for (int i = 0; i < M; i++) {
			StdOut.print(a[i] + " ");
		}
		StdOut.println();
	}
}
